Wiki

Clone wiki

lifev-release / tutorial / Creation_of_the_FESpace

Go back


Creation of the FESpace

There are two main classes that provide the tools to create a finite element space:

  • the FESpace class, which contains the basic definitions and operations to create and manipulate a finite element space;
  • the ETFESpace class, that contains some advanced definitions to perform the assembly of the linear system.

To create a finite element space, we have to:

  1. include the header files that contain the definitions of the classes FESpace and ETFESpace;
  2. define a type for the maps used to manage the degrees of freedom;
  3. define the FESpace and then define the ETFESpace.

First of all, we add the following two header files:

#!C++
// ...
// Header for the Finite Element Space
#include <lifev/core/fem/FESpace.hpp>
// Header for the ET Finite Element Space
#include <lifev/eta/fem/ETFESpace.hpp>
// ...
Inside the main function, we create an alias for the MapEpetra type:
#!C++
// ...
int main ( Int argc, char** argv )
{
    // ...
    typedef MapEpetra map_Type;
    // ...
Now, we define a pointer to the FESpace that depends on the type of the mesh and the type of the map.

As input parameters, it requires the local (possibly partitioned) mesh, the type of the finite element (e.g. P1, P1b, P2 and so on), the dimension of the field (1: scalar, 3: vectorial) and the communicator.

Finally, we can define a pointer to the ETFESpace that depends on i) the type of the mesh, ii) the type of the map, iii) the dimension of the physical space (1, 2 or 3) and iv) the dimension of the field (1: scalar, 3: vectorial). The constructor requires the local (possibly partitioned) mesh, the reference element (obtained from the FESpace), the geometrical mapping from the reference to the current element (obtained from the FESpace) and the communicator.

#!C++
    // ...

    // Defining the classical Finite Element Space (for scalar field)
    std::shared_ptr< FESpace< mesh_Type, map_Type> > uFESpace
        ( new FESpace< mesh_Type, map_Type> ( local_mesh,
                                              dataFile ( "finite_element/degree", "P1" ),
                                              1,
                                              Comm ) );

    // Creating the ET Finite Element Space (3 dimensional, scalar field)
    // based on the classical Finite Element Space previously declared
    std::shared_ptr< ETFESpace< mesh_Type, map_Type, 3, 1 > > uETFESpace
        ( new ETFESpace< mesh_Type, map_Type, 3, 1 > ( local_mesh,
                                                       & ( uFESpace->refFE() ),
                                                       & ( uFESpace->fe().geoMap() ),
                                                       Comm) );

    // ...
In the next snippet of code, we check if the FE space has been created by printing the total number of degrees of freedom:

#!C++
    // ...

    if ( Comm->MyPID() == 0 )
    {
        // Total number of Dofs created
        std::cout << "\nUsing " << uETFESpace->dof().numTotalDof() << " Dofs\n\n";
    }

    // ...
Here you can download the complete main file mainCreatingFESpace.cpp, the mesh file cube.mesh and dataFESpace.in file.

Updated